/*
 * @ProjectName: 编程学习
 * @Copyright:   2024 HangZhou soukyuu Dev, Ltd. All Right Reserved.
 * @address:     微信搜索公众号「架构探险之道」获取更多资源。
 * @date:        2024/7/14 23:09
 * @blog:         https://yiyuery.blog.csdn.net/
 * @description: 本内容仅限于编程技术学习使用，转发请注明出处.
 */
package com.capsule.leetcode.LC80;

import org.springframework.util.StringUtils;

import java.text.MessageFormat;
import java.util.*;

/**
 * <p>
 *
 * </p>
 *
 * @author soukyuu
 * @date 2024/7/14 23:09
 * @since 1.0.0
 */
public class Answer {

    public static void main(String[] args) {
        int[] nums = {1,1,1,2,2,3};
        process(nums);
    }

    private static int process(int[] nums) {

        /*

         0,0,1,1,1,2,2,3
         0,0,1,1,2,2,3

         0,0
         loop 0,0 -> continue
         loop clear -> continue
         loop 1,1 -> continue
         loop clear -> continue
         loop 2,2 -> continue
         */
        int cnt = 0;
        int temp = -1000;
        int[] result = new int[nums.length];
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            if (cnt > 0) {
                if (temp != nums[i]) {
                    cnt=1;
                    temp = nums[i];
                    result[index++] = nums[i];
                }else if (temp == nums[i]) {
                    cnt++;
                    if (cnt < 3) {
                        result[index++] = nums[i];
                    }
                }
            }else if(cnt == 0){
                temp = nums[i];
                cnt = 1;
                result[index++] = nums[i];
            }

            System.out.println(MessageFormat.format("cnt:{0},temp:{1},result:{2},length:{3}",cnt,temp,Arrays.toString(result),result.length));

        }

        for (int i = 0; i < index; i++) {
            nums[i] = result[i];
        }

        System.out.println( nums.length + " , nums="+Arrays.toString(nums));
        System.out.println( result.length + " , nums="+Arrays.toString(result));
        return index;
    }

}
